<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1,minimum-scale=1,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>省钱控商品列表</title>
    <link rel="stylesheet" href="../css/base.css">
    <link rel="stylesheet" href="../css/海淘折扣页面.css">
    <link rel="stylesheet" href="../css/iconfont.css">
</head>

<body>
    <header>
        <div class="iconfont  icon-xiazai6"></div>
        <div class="zx-h-title">省钱控 - 最新优惠</div>
        <div class="iconfont icon-xiazai">
            <p>下载APP</p>
        </div>
    </header>
    <div class="sqk-content">
        <ul class="ul-sqk">

        </ul>
    </div>

    <div class="fy">
        <div class="fy-l">
            <span class="uppage">上一页</span>
        </div>
        <div class="fy-m">
            <select class="hgy_content">

            </select>
        </div>
        <div class="fy-r">
            <span class="downpage">下一页</span>
        </div>
    </div>
    <footer>
        <!-- 底部工具栏 -->
        <div class="footer-tools">
            <a href="javascript:;">登录</a>
            <a href="javascript:;">注册</a>
            <a href="javascript:;">返回顶部</a>
        </div>
        <!-- 版权信息 -->
        <div class="footer-copyright">
            <p>
                <a href="javascript:;">手机APP下载</a>
                慢慢买手机版
                <span>-- 掌上比价平台</span>
            </p>
            <p>m.manmanbuy.com</p>
        </div>
    </footer>
</body>

</html>
<script src="../js/jquery.min.js"></script>
<script src="../js/template.js"></script>
<script type="text/template" id="usersListTmp">
    {{each result as val key}}
        <li>
            <a href="../buy_slowly-list.html?productid={{val.productId}}">
                <div class="sqk-list">
                <div class="sqk-list-left">{{val.productImg2}}</div>
                    <div class="sqk-list-right">
                        <p>{{val.productName}}<span>{{val.productPinkage}}</span></p>
                        <p>{{val.productFrom}} | {{val.productTime}} <span>{{val.productComCount}}</span></p>
                    </div>
                </div>
            </a>
        </li>
    {{/each}}
</script>

<script>
    $.ajax({
        type: 'get', //  请求的类型
        url: 'http://193.112.55.79:9090/api/getmoneyctrl', // 请求的目标地址
        dataType: 'json', // 数据回来之后解析成的类型

        success: function (res) {
            // console.log(res);
            // console.log(res.pagesize);
            var content = Math.ceil(res.totalCount / 10);
            // var pagesize = res.pagesize;
            // var pageid = res.result[0].productId / 10 - 1;
            // var data = {
            //     content: content,
            //     pageid: pageid
            // };
            // console.log(data);
            // // res.result['pageid'] = pageid;
            // // res.result['content'] = content;
            // console.log(res);
            template.config("escape", false);
            var htmlStr = template('usersListTmp', res);
            $('.ul-sqk').html(htmlStr);

            var str = "";
            for (var i = 1; i <= content; i++) {
                str += '<option>' + i + '/' + content + '</option>';
            }
            // console.log(str);
            $('.hgy_content').html(str);

            $('select').on('click', function () {
                var pageid = $(this)[0].value;

                console.log(pageid);

                if (pageid.length == 4) {
                    pageid = pageid.substring(0, 1);
                } else {
                    pageid = pageid.substring(0, 2);
                }
                // console.log(pageid);
                // console.log(pageid);
                $.ajax({
                    type: 'get',
                    url: 'http://193.112.55.79:9090/api/getmoneyctrl',
                    data: {
                        pageid: pageid - 1
                    },
                    dataType: 'jsonp',
                    success: function (res) {
                        if (res) {
                            template.config("escape", false);
                            var htmlStr = template('usersListTmp', res);
                            $('.ul-sqk').html(htmlStr);
                        }
                    }
                })
            })



            $('.downpage').click(function () {


                var value = $('select')[0].value;
                var pageid = $('select')[0].value;
                if (pageid.length == 5) {
                    pageid = parseInt(pageid.substring(0, 2));
                    if (pageid == 15) {
                        return;
                    } else {
                        pageid = pageid + 1;
                        $('select')[0].value = pageid + value.substring(2);
                    }


                } else if (pageid.length == 4) {
                    pageid = parseInt(pageid.substring(0, 1)) + 1;

                    $('select')[0].value = pageid + value.substring(1);


                }


                $.ajax({
                    type: 'get',
                    url: 'http://193.112.55.79:9090/api/getmoneyctrl',
                    data: {
                        pageid: pageid - 1
                    },
                    dataType: 'jsonp',
                    success: function (res) {
                        if (res) {
                            template.config("escape", false);
                            var htmlStr = template('usersListTmp', res);

                            $('.ul-sqk').html(htmlStr);
                        }


                    }
                })


            })

            $('.uppage').on('click', function () {
                console.log($('select')[0].value);
                var value = $('select')[0].value;
                // var pageid=$('select')[0].value.substring(0,1);
                var pageid = $('select')[0].value;
                // $('select')[0].value=pageid-1+value.substring(1);
                // console.log($('select')[0].value);
                if (pageid.length == 4) {
                    pageid = pageid.substring(0, 1);
                    if (pageid == 1) {
                        return
                    } else {
                        $('select')[0].value = pageid - 1 + value.substring(1);
                        pageid = pageid - 1;
                        // console.log(pageid)
                    }
                } else if (pageid.length == 5) {
                    pageid = pageid.substring(0, 2);
                    $('select')[0].value = pageid - 1 + value.substring(2);
                    pageid = pageid.substring(0, 2) - 1;
                    // pageid=parseInt(pageid);
                    console.log(pageid);
                }

                $.ajax({
                    type: 'get',
                    url: 'http://193.112.55.79:9090/api/getmoneyctrl',
                    data: {
                        pageid: pageid - 1
                    },
                    dataType: 'jsonp',
                    success: function (res) {
                        if (res) {
                            template.config("escape", false);
                            var htmlStr = template('usersListTmp', res);

                            $('.ul-sqk').html(htmlStr);
                        }
                    }
                })

            })
        }
    })


    //
</script>